// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-14

#ifndef __CLNTSOCKET_H_CLIENT_MAIN__
#define __CLNTSOCKET_H_CLIENT_MAIN__

#pragma once

#include <common\netmsg\msgsocket.h>

//##ModelId=44C4B5E600AD
class CJoyClientMsgHandler
{
public:
#   define JOY_MSG_SERVER_DEF(name) virtual void OnMsg_##name(const JoyMessage::MS_##name*) {}
#   include <common\netmsg\ms_def.h>

	//##ModelId=44C4B5E600BB
    virtual void OnMsg_Invalid(const JoyMessage::MessageBase* msg);

	//##ModelId=44C4B5E600BE
    virtual void OnSock_Connect(int ){}
	//##ModelId=44C4B5E600CB
    virtual void OnSock_Close( ){}

	//##ModelId=44C4B5E600CD
    virtual void OnSock_Error(int ){}
	//##ModelId=44C4B5E600D0
    virtual void OnSock_BadData(){}
};

//##ModelId=44C4B5E600DA
class CJoyClientSocket :
    public CJoyMsgSocket
{
protected:
	//##ModelId=44C4B5E600DC
    virtual CJoySockData* OnCreateData();

    template<typename MsgType>
    void OnDispatchMessage(const MsgType* msg, void (CJoyClientMsgHandler::*pHandler)(const MsgType*));

	//##ModelId=44C4B5E600EA
    virtual void OnConnect(int nErrorCode);
	//##ModelId=44C4B5E600ED
    virtual void OnClose();

	//##ModelId=44C4B5E600EF
    virtual void OnJoyMsg(const JoyMessage::MessageBase* msg);
public:
	//##ModelId=44C4B5E600FC
    CJoyClientMsgHandler*   m_handler;
public:
	//##ModelId=44C4B5E60100
    CJoyClientSocket(void);
	//##ModelId=44C4B5E60102
    virtual ~CJoyClientSocket(void);

	//##ModelId=44C4B5E60109
    bool ConnectServer(const CString& strIP, UINT nPort);
	//##ModelId=44C4B5E6010C
    void DisconnectServer();
};



#endif  // __CLNTSOCKET_H_CLIENT_MAIN__
